[SUBROUTINE]
version = 1.14
icon = rect-array.png
name = _("Rectangular Array")
type = rect-array
indent = 1
help = _("<b>Create a Rectangular Array of items</b>")
order = act h1 x alx y aly z h2 numx dx numy dy h3 r xr yr items

[PARAM_ACT]
name = _("Active")
icon = enable.png
type = bool
value = 1
tool_tip = _("Disabling will disable ALL items")

[PARAM_H1]
type = sub-header
name = _("Coords")
tool_tip = _("Origin")

[PARAM_ALX]
name = _("X axis align")
icon = align-x.png
type = combo
options = _("Left=0:Center=1:Right=2")
value = 0
tool_tip = _("Define X reference")
header = h1

[PARAM_ALY]
name = _("Y axis align")
icon = align-y.png
type = combo
options = _("Top=0:Center=1:Bottom=2")
value = 2
tool_tip = _("Define Y reference")
header = h1

[PARAM_H2]
type = sub-header
name = _("Size and offsets")

[PARAM_H3]
type = sub-header
name = _("Rotation")

[PARAM_NUMX]
name = _("X axis copies")
type = int
minimum_value = 1
icon = copies.png
tool_tip = _("Number of copies")
value = 2
header = h2

[PARAM_NUMY]
name = _("Y axis copies")
type = int
minimum_value = 1
icon = copies.png
tool_tip = _("Number of copies")
value = 3
header = h2

[PARAM_X]
name = _("X")
type = float
icon = x.png
tool_tip = _("Origin X")
value = 0
metric_value = 0
header = h1

[PARAM_Y]
name = _("Y")
type = float
icon = y.png
tool_tip = _("Origin Y")
value = 0
metric_value = 0
header = h1

[PARAM_Z]
name = _("Z")
type = float
value = 0
metric_value = 0
header = h1
hidden = 1

[PARAM_R]
name = _("Array rotation")
type = float
digits = 2
icon = angle.png
tool_tip = _("Rotation of array")
value = 0
header = h3
suffix = &#176;

[PARAM_DX]
name = _("dX")
type = float
icon = dx.png
tool_tip = _("X step")
value = 1
metric_value = 25
header = h2

[PARAM_XR]
name = _("X items rotation")
type = float
digits = 2
icon = angle.png
tool_tip = _("Relative to previous one")
value = 0
header = h3
suffix = &#176;

[PARAM_DY]
name = _("dY")
type = float
icon = dy.png
tool_tip = _("Y step")
value = 1
metric_value = 25
header = h2

[PARAM_YR]
name = _("Y items rotation")
type = float
digits = 2
icon = angle.png
tool_tip = _("Relative to previous one")
value = 0
header = h3
suffix = &#176;

[PARAM_ITEMS]
name = _("Items")
type = items
icon = items.png
tool_tip = _("Items to copy")

[DEFINITIONS]
content =
;	<eval>self.include_once(file name here)</eval>

[BEFORE]
content =
	(begin #sub_name)
	(rectangular array author : Fernand Veilleux)
	
	o<#self_id_active> if [#param_act]
		o<select> CALL [31] [#param_alx] [#param_x] [#param_x - [#param_numx - 1] * #param_dx / 2] [#param_x - [#param_numx - 1] * #param_dx]
		#<first_x#ID> = #31
	
		o<select> CALL [31] [#param_aly] [#param_y - [#param_numy - 1] * #param_dy] [#param_y - [#param_numy - 1] * #param_dy / 2] [#param_y]
		#<first_y#ID> = #31
	
		(get and save current coords system offsets)
		#<old_coord_system#ID> = [#<_coord_system> / 10]
		o<get_offsets> CALL
		#<offset_x#ID> = #<_offsets_x>
		#<offset_y#ID> = #<_offsets_y>
		#<offset_z#ID> = #<_offsets_z>
		#<offset_r#ID> = #<_offsets_r>
		
		(change coords system)
		G#<_off_rot_coord_system>
		
		#<start_y#ID>  = [#<offset_y#ID> + #<first_y#ID>]
		#<items_yr#ID> = 0
		#<x_step#ID>   = 1
		#<x_round#ID>  = 0
		#<start_x#ID>  = [#<offset_x#ID> + #<first_x#ID>]
		#<items_xr#ID> = 0
		o<#self_id_loop_Y> repeat [#param_numy]
			o<#self_id_loop_X> repeat [#param_numx]
				(get rotated coordinates then apply to new coords)
				#<rot#ID> = [#<offset_r#ID> + #param_r + #<items_xr#ID> + #<items_yr#ID>]
				o<rotate_xy> CALL [#<start_x#ID>] [#<start_y#ID>] [#<offset_x#ID> + #param_x] [#<offset_y#ID> + #param_y] [#<offset_r#ID> + #param_r]
				o<#self_id_change_coords> if [#<_has_z_axis>]
					G10 L2 P#5220 X[#<_rotated_x>] Y[#<_rotated_y>] Z#<offset_z#ID> R[#<rot#ID>]
				o<#self_id_change_coords> else
					G10 L2 P#5220 X[#<_rotated_x>] Y[#<_rotated_y>] R[#<rot#ID>]
				o<#self_id_change_coords> endif
				
				(begin #sub_name items)

[AFTER]
content =
				(end #sub_name items)
	
				#<x_round#ID> = [#<x_round#ID> + #<x_step#ID>]
				o<#self_id_inc> if [[#<x_round#ID> LT #param_numx] AND [#<x_round#ID> GT 0]]
					#<start_x#ID>  = [#<start_x#ID>  + #param_dx * #<x_step#ID>]
					#<items_xr#ID> = [#<items_xr#ID> + #param_xr * #<x_step#ID>]
				o<#self_id_inc> endif
			o<#self_id_loop_X> endrepeat
	
			#<x_step#ID>   = [#<x_step#ID>   * -1]
			#<start_y#ID>  = [#<start_y#ID>  + #param_dy]
			#<items_yr#ID> = [#<items_yr#ID> + #param_yr]
		o<#self_id_loop_Y> endrepeat
	
		(restore coordinate system)
		G#<old_coord_system#ID>
		o<#self_id_restore_coords> if [#<_has_z_axis>]
			G10 L2 P#5220 X#<offset_x#ID> Y#<offset_y#ID> Z#<offset_z#ID> R#<offset_r#ID>
		o<#self_id_restore_coords> else
			G10 L2 P#5220 X#<offset_x#ID> Y#<offset_y#ID> R#<offset_r#ID>
		o<#self_id_restore_coords> endif
		
	o<#self_id_active> endif
	(end #sub_name)
